const Base = require('./base.js');

module.exports = class extends Base {
  /**
   * 保存意见反馈及留言
   * @returns {Promise.<Promise|PreventPromise|void>}
   */
  async saveAction() {
    let feedbackId = this.post('id');

    const addressData = {
      user_id: this.getLoginUserId(),
      user_mobile: this.post('user_mobile'),
      msg_content: this.post('msg_content'),
      msg_time:new Date()
    };

    if (think.isEmpty(feedbackId)) {
      feedbackId = await this.model('feedback').add(addressData);
    } else {
      await this.model('feedback').where({id: feedbackId, user_id: this.getLoginUserId()}).update(addressData);
    }
    const feedbackInfo = await this.model('feedback').where({id: feedbackId}).find();

    return this.success(feedbackInfo);
  }
};
